package com.dataguru.hadoop.week2;

/**
 * Created by fan.shijun on 2015-04-22.
 */

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.net.URI;

public class MinTemperature {

    public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            System.err.println("Usage: MinTemperature<input path> <output path>");
            System.exit(-1);
        }
        Configuration config = new Configuration();
        FileSystem hdfs = FileSystem.get(URI.create(args[1]), config);
        Path inputDir = new Path(args[0]);
        Path outputDir = new Path(args[1]);
        if (hdfs.exists(outputDir)) {
            hdfs.delete(outputDir, true);
        }
        Job job = new Job(config, "Mintemperature");
        job.setJarByClass(MinTemperature.class);
        FileInputFormat.setInputPaths(job, inputDir);
        FileOutputFormat.setOutputPath(job, outputDir);
        job.setMapperClass(MinTemperatureMapper.class);
        job.setReducerClass(MinTemperatureReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        job.waitForCompletion(true);
    }
}
